RegexMatching
You may want to read the extension documentation if you have questions about how extensions work
Example
Create an extension & implement onSourceFileFound
or another function.
1. Define your regex(es)
protected $regex = [
'wrappedGenericBlock' => [ // 'wrappedGenericBlock' is the function to call
// 'function'=> 'functionName' <- to override the regex set's name
//For this regex: $1 is the key, $2 is the code, $3 is the @export_end line
'/\ *(?:\/\/|\#)\ *@export_start\(([^\)]*)\)((?:.|\r|\n)+)\ *(?:\/\/|\#)\ *(@export_end\(\1\))/',
// You can list additional regexes here
]
];
2. Write your onMatch function(s)
/**
* @param $name The name of the matched regex set
* @param $match an individual preg_match_all match, using PREG_SET_ORDER ([0] is full match. [1] is capture group & so on)
* @param \Tlf\Scrawl\File $file The file that was matched on. Or null if not given to Regex::matchRegexes()
* @param $info an array of additional information. print_r(array_keys($info)) or look at the docs
*
* @export(Regex.onMatchBlock)
*/
public function wrappedGenericBlock($name, $match, ?File $file, $info) {
$exportBlock = $match;
$key = $exportBlock[1];
$code = $exportBlock[2];
$exportLine = $exportBlock[3];
$code = Utility::trimTextBlock($code);
$this->scrawl->addOutput('key', $key, $code);
}
3. Call Regex Utility
public function onSourceFileFound($file){
\Tlf\Scrawl\Regex::matchRegexes($this, $this->regex, $file);
}
The $info array
$info = [
'matchList'=>$matches, // Array of all matches
'lineStart' => -1, // (not implemented, @TODO) Line in file/text that your match starts on
'lineEnd' => -1, // (not implemented, @TODO) Line in file/text that your match ends on
'text' => $text, //
'regIndex' => null,
];